<template>
  <div>
    <div class="text-center">
      <UserAvatar />
    </div>
    <ul class="list-group list-group-striped">
      <li class="list-group-item">
        <svg-icon icon-class="UserFilled" style="font-size: 18px"></svg-icon>
        {{ $t("personal.Benutzername") }}
        <div class="pull-right">{{ formData.nickname }}</div>
      </li>
      <li class="list-group-item">
        <svg-icon icon-class="phoneFilled" style="font-size: 18px" />
        {{ $t("personal.Mobiltelefonnummer") }}
        <div class="pull-right">{{ formData.mobile }}</div>
      </li>
      <li class="list-group-item">
        <svg-icon icon-class="renzheng" style="font-size: 18px" />
        {{ $t("personal.JobStudentenausweis") }}
        <div class="pull-right">{{ formData.codeId }}</div>
      </li>
      <li class="list-group-item">
        <svg-icon icon-class="connection-box" style="font-size: 18px" />
        {{ $t("personal.VerbundeneOrganisation") }}
        <div class="pull-right">{{ formData.deptName }}</div>
      </li>
      <li class="list-group-item">
        <svg-icon icon-class="peoples" style="font-size: 18px" />
        {{ $t("personal.Rolle") }}
        <div class="pull-right">{{ formData.roleName }}</div>
      </li>
      <li class="list-group-item">
        <svg-icon icon-class="calendar" style="font-size: 18px" />
        {{ $t("personal.Erstelltauf") }}
        <div class="pull-right">
          {{ formData.createTime }}
        </div>
      </li>
    </ul>
  </div>
</template>
<script lang="ts" setup>
defineOptions({ name: "ProfileUser" });
import UserAvatar from "./UserAvatar.vue";
import SvgIcon from "@/components/SvgIcon/index.vue";
import { useUserStore } from "@/store/modules/user";
import { PersonInfo } from "@/api/personal/types";
import { getpersonInfo } from "@/api/personal";

// 重要 ：使用 defineExpose 声明父组件要调用的方法
defineExpose({
  getprofileinfo,
});

const userStore = useUserStore();

const formData = reactive<PersonInfo>({
  avatarUrl: "",
  roleName: "",
  codeId: "",
});

function getprofileinfo() {
  getpersonInfo(userStore.userId).then(({ data }) => {
    formData.nickname = data.nickname;
    formData.mobile = data.mobile;
    formData.deptName = data.deptName;
    formData.roleName = data.roleName;
    formData.createTime = data.createTime;
    formData.codeId = data.codeId;
  });
}

onMounted(() => {
  getprofileinfo();
});
</script>

<style scoped>
.text-center {
  text-align: center;
  position: relative;
  height: 160px;
}

.list-group-striped > .list-group-item {
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
}

.list-group {
  padding-left: 0;
  list-style: none;
}

.list-group-item {
  border-bottom: 1px solid #e7eaec;
  border-top: 1px solid #e7eaec;
  margin-bottom: -1px;
  padding: 11px 0;
  font-size: 13px;
}

.pull-right {
  float: right !important;
}
</style>
